class MyPage extends BaseList {
    constructor(action, orderby, flag, $pagesize, $pagination, cokiePageSize, cokiePageIndex, cokieListResult, listUrl, delUrl) {
        super(action, orderby, flag, $pagesize, $pagination, cokiePageSize, cokiePageIndex, cokieListResult, listUrl, delUrl);
    }
    OnPageLoad() {
        $("#Option2").hide();
        let _currentDate = new Date();
        $("#YearOfBill").val(_currentDate.getFullYear());
        $("#MonthOfBill").val(_currentDate.getMonth() + 1);

        // 回车直接进行搜索
        $("panel_search").bind('keyup', function (e) {
            var key = e.keyCode;
            if (key === 13) {
                _Instance.Fetch();
            }
        });
        $('#loading').hide();
    }
    SetCriterion(item) {
        // 设置材料检索条件       
        if (parseInt($("#searchOption").val()) === 1) {
            item['YearOfBill'] = $("#YearOfBill").val();
            item['MonthOfBill'] = $("#MonthOfBill").val();
        } else {
            item['Begin'] = $("#Begin").val();
            item['End'] = $("#End").val();
        }
        item['Flag'] = $("#searchOption").val();
        item['SupplierNameFilterValue'] = $.trim($("#SupplierNameFilterValue").val()) === "" ? null : $.trim($("#SupplierNameFilterValue").val());
        item['PoNo'] = $.trim($("#PoNoFilterValue").val()) === "" ? null : $.trim($("#PoNoFilterValue").val());
        return item;
    }
    GetFilter() {
        let item = super.GetFilter(0);
        // 设置条件
        item = this.SetCriterion(item);
        return JSON.stringify(item);
    }
    EmptyTableContent() {
        $("#tab_data01 tbody").empty();
    }
    SetTableContent(result) {
        $("#tab_data01 tbody").empty();

        let content_01 = '';
        this.rows = result.length;
        for (let i = 0; i < result.length; i++) {
            content_01 += '<tr >';
            content_01 += '<td>' + formatNullData(result[i].supplierName) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].poNo) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].styleNo) + '</td>';
            content_01 += '<td style="text-align:right;">' + formatNullData(result[i].amount) + '</td>';
            var _surchargeName = "";
            if (result[i].surchargeName === null || result[i].surchargeName === '') {
                _surchargeName = "附加费（小缸费/染费）";
            } else {
                _surchargeName = result[i].surchargeName;
            }
            content_01 += '<td>' + formatNullData(_surchargeName) + '</td>';
            var _monthValue = "";
            if (parseInt($("#searchOption").val()) === 1) {
                _monthValue = $("#MonthOfBill").val();
            } else {
                _monthValue = $("#Begin").val().substr(5, 2);
            }
            content_01 += '<td style="text-align:center;">' + _monthValue + '</td>';
            content_01 += '</tr>';
            $("#tab_data01 tbody").append(content_01);
            content_01 = '';
        }
        setOneTableRowColor("tab_data01");

        this.AutoAdjustTableHeightForLines();   // 自适应高度设置
        $(window).resize();                     // 防止因为出现滚动条而造成画面显示问题
        $('#loading').hide();
    }
    //《按钮》搜索
    DoSearch() {
        if (parseInt($("#searchOption").val()) === 1) {
            if (formatNullInputValue($.trim($("#YearOfBill").val())) === null) {
                ShowErrorMessagePanel('对账年的检索条件不能空');
            } else {
                this.FetchForPage(1);
            }
        } else {
            if (formatNullInputValue($.trim($("#Begin").val())) === null || formatNullInputValue($.trim($("#End").val())) === null) {
                ShowErrorMessagePanel('落单日期的检索条件不能空');
            } else {
                this.FetchForPage(1);
            }
        }
    }
    OnSelectOption() {
        if (parseInt($("#searchOption").val()) === 1) {
            $("#Option1").show();
            $("#Option2").hide();
        } else {
            $("#Option2").show();
            $("#Option1").hide();
        }
    }
    AutoAdjustTableHeightForLines() {
        let h = $(window).height();
        let _rc = Math.floor((h - 147 - 25) / 25);
        let _dh = _rc * 25;
        let _tah = this.rows * 25;
        _dh = (_tah >= _dh) ? _dh : _tah;

        $("#div_content").css({"max-height": _dh, height: _dh});
    }
}

var _Instance = null;

//-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
    $("#search_btn").hide(); // 无需搜索，隐藏搜索按钮
    $("#PoNoFilterValue").bigAutocomplete({
        url: parent.basePath + "/purchase/mpc/fetchPoNoForAutoComplate.html"
    });

    _Instance = new MyPage(0, null, null, null, null, null, null, null,
            "/purchase/report/surcharge/fetchAll.html",
            "");

    window.laydate.render({
        elem: '#Begin',
        theme: '#393D49',
        trigger: 'click'
    });
    window.laydate.render({
        elem: '#End',
        theme: '#393D49',
        trigger: 'click'
    });

    _Instance.OnPageLoad();
}

// 画面大小或者位置移动
function onPageResize() {
    if (_Instance !== null)
        _Instance.AutoAdjustTableHeightForLines();
}